package com.xdjd.mobile.business.api.challenge;

import com.gitee.easyopen.annotation.Api;
import com.gitee.easyopen.annotation.ApiService;
import com.gitee.easyopen.doc.DataType;
import com.gitee.easyopen.doc.annotation.ApiDoc;
import com.gitee.easyopen.doc.annotation.ApiDocField;
import com.gitee.easyopen.doc.annotation.ApiDocMethod;
import com.gitee.easyopen.exception.ApiException;
import com.xdjd.mobile.business.api.BaseApi;
import com.xdjd.mobile.business.entity.param.BasePageParam;
import com.xdjd.mobile.business.entity.param.challenge.BaseChallengeParam;
import com.xdjd.mobile.business.entity.param.challenge.BaseStepParam;
import com.xdjd.mobile.business.entity.param.challenge.ChallengeUserParam;
import com.xdjd.mobile.business.entity.param.challenge.RandomChallengeParam;
import com.xdjd.mobile.business.entity.param.challenge.*;
import com.xdjd.mobile.business.entity.result.challenge.*;
import com.xdjd.mobile.business.entity.vo.ChallengeMyPkResult;
import com.xdjd.mobile.business.entity.vo.ChallengeMyPkVO;
import com.xdjd.mobile.business.entity.vo.ChallengeRoomInfoVO;
import com.xdjd.mobile.business.entity.vo.LoginUser;
import com.xdjd.mobile.business.service.ChallengeService;
import com.xdjd.mobile.system.ApiUtil;
import net.oschina.durcframework.easymybatis.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;

/**
 * Created by Administrator on 2019/1/9 0009.
 */
@ApiService
@ApiDoc("挑战游戏")
public class ChallengeApi extends BaseApi {

    @Autowired
    private ChallengeService challengeService;

    @Api(name = "user.step.update")
    @ApiDocMethod(description = "更新用户步数")
    public void updateStep(BaseStepParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        challengeService.updateStep(param.getStepNumber(), currentUser.getId());
    }

    @Api(name = "nologin.random.challenge.list")
    @ApiDocMethod(description = "首页")
    public RandomChallengeResult randomChallengeList(RandomChallengeParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        return challengeService.randomChallengeList(currentUser == null ? null : currentUser.getId(), param.getCount());
    }

    @Api(name = "challenge.user")
    @ApiDocMethod(description = "用户挑战")
    public void challengeUser(ChallengeUserParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        challengeService.challengeUser(currentUser.getId(), param.getRecordNo(), param.getStepNumber());
    }

    @Api(name = "challenge.record.get")
    @ApiDocMethod(description = "获取挑战记录列表", results = {@ApiDocField(name = "pageIndex", description = "第几页", dataType = DataType.INT, example = "1"),
            @ApiDocField(name = "pageSize", description = "每页几条数据", dataType = DataType.INT, example = "2"),
            @ApiDocField(name = "total", description = "总记录数", dataType = DataType.LONG, example = "100"),
            @ApiDocField(name = "list", description = "数据", dataType = DataType.ARRAY, elementClass = ChallengeRecordResult.class),})
    public PageInfo<ChallengeRecordResult> getChallengeList(BasePageParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        return challengeService.getChallengeList(param, currentUser.getId());
    }

    @Api(name = "challenge.bechallenge.record.get")
    @ApiDocMethod(description = "守擂记录", results = {@ApiDocField(name = "pageIndex", description = "第几页", dataType = DataType.INT, example = "1"),
            @ApiDocField(name = "pageSize", description = "每页几条数据", dataType = DataType.INT, example = "2"),
            @ApiDocField(name = "total", description = "总记录数", dataType = DataType.LONG, example = "100"),
            @ApiDocField(name = "list", description = "数据", dataType = DataType.ARRAY, elementClass = BeChallengeRecordResult.class),})
    public PageInfo<BeChallengeRecordResult> findBeChallengeRecord(BasePageParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        return challengeService.getBeChallengeList(param, currentUser.getId());
    }

    @Api(name = "challenge.challenge.record.get")
    @ApiDocMethod(description = "挑战记录", results = {@ApiDocField(name = "pageIndex", description = "第几页", dataType = DataType.INT, example = "1"),
            @ApiDocField(name = "pageSize", description = "每页几条数据", dataType = DataType.INT, example = "2"),
            @ApiDocField(name = "total", description = "总记录数", dataType = DataType.LONG, example = "100"),
            @ApiDocField(name = "list", description = "数据", dataType = DataType.ARRAY, elementClass = ChallengeRecordsResult.class),})
    public PageInfo<ChallengeRecordsResult> findChallengeRecordsList(BasePageParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        return challengeService.getChallengeRecordsList(param, currentUser.getId());
    }

    @Api(name = "my.challenge.detail")
    @ApiDocMethod(description = "我的守擂")
    public MyChallengeResult findMyChallenge(BaseChallengeParam param) {
        return challengeService.findMyChallenge(param);
    }

    @Api(name = "challenge.room.info")
    @ApiDocMethod(description = "挑战房间信息")
    public ChallengeRoomInfoVO challengeRoomInfo(ChallengeRoomInfoParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        Long curUserId = currentUser.getId();
        ChallengeRoomInfoVO challengeRoomInfoVO = challengeService.challengeRoomInfo(curUserId, param.getRecordNo());
        if (challengeRoomInfoVO != null) {
            challengeRoomInfoVO.setMyImage(currentUser.getImage());
        }
        return challengeRoomInfoVO;

    }

    @Api(name = "challenge.my.pk")
    @ApiDocMethod(description = "我的pk")
    public ChallengeMyPkResult challengeMyPk() {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        return challengeService.challengeMyPk(currentUser.getId());

    }


}
